package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.annotation.Log;
import com.itheima.mapper.ClazzMapper;
import com.itheima.pojo.*;
import com.itheima.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;

@Service
public class ClassServiceImpl implements ClassService {
    @Autowired
    private ClazzMapper clazzMapper;
    @Override
    public PageResult<Clazz> findAll(ClazzQueryParam param) {
        PageHelper.startPage(param.getPage(),param.getPageSize());
        List<Clazz> clazzList = clazzMapper.findAll(param);
        Page<Clazz> p = (Page<Clazz>)clazzList;
        PageResult<Clazz> pageResult = new PageResult<>(p.getTotal(),clazzList);
        return pageResult;
    }
    @Log
    @Override
    public void add(Clazz clazz) {
        clazz.setCreateTime(LocalDateTime.now());
        clazz.setUpdateTime(LocalDateTime.now());
        clazzMapper.add(clazz);
    }
    @Log
    @Override
    public void delete(Integer id) {
        clazzMapper.delete(id);
    }

    @Override
    public Clazz findById(Integer id) {
        Clazz clazz = clazzMapper.findById(id);
        return clazz;
    }

    @Override
    public List<Clazz> list() {
        return clazzMapper.list();
    }
    @Log
    @Override
    public void update(Clazz clazz) {
        clazz.setUpdateTime(LocalDateTime.now());
        clazzMapper.update(clazz);
    }
    /*public PageResult<Emp> page(EmpQueryParam param) {
        //设置分页参数
        PageHelper.startPage(param.getPage(),param.getPageSize());
        //执行查询
        List<Emp> empList = empMapper.list(param);
        //解析查询结果并封装
        Page<Emp> p = (Page<Emp>)empList;
        PageResult<Emp> pageResult = new PageResult<>(p.getTotal(),empList);
        return pageResult;
    }*/
}
